//FxLock V2 //D'AVENIA Nicolas //nicoda57@gmail.com //www.top-progcasio.com #include "fxlib.h" FONTCHARACTER pinFile[]={'\\','\\','f','l','s','0','\\','p','f','i','l','e','.','d','a','t',0}; int worb=1; void clignote() { int i,j; worb=-worb; if(worb==1) { for(i=123;i<=127;i++)for(j=0;j<=4;j++)Bdisp_SetPoint_DD(i,j,1); } else { Bdisp_PutDisp_DD(); } } int matchCode(unsigned char * pass1, unsigned char * pass2) { while(*pass1==*pass2){ if(*pass1==0)return 1; pass1++; pass2++; } return 0; } void getUserCode(int pos_x, int pos_y, unsigned char * pass){ unsigned int key; unsigned char etoile[2]={0x2A,0}; int pos=0; SetTimer(1,350,clignote); do{ GetKey(&key); if(key>=48 && key<=58 && pos<8) { locate((pos_x+pos),pos_y); pass[pos]=(unsigned char)key; Print((unsigned char*)etoile); pos++; } if(key==KEY_CTRL_DEL && pos>0) { pos--; locate((pos_x+pos),pos_y); Print((unsigned char*)" "); } }while(key!=KEY_CTRL_EXE || pos==0); pass[pos]=0; KillTimer(1); } void readPassword(unsigned char * buf){ int file; file=Bfile_OpenFile(pinFile,_OPENMODE_READ); Bfile_ReadFile(file ,buf ,9,1); Bfile_CloseFile(file); } void setPassword(unsigned char * pass){ int file; unsigned char buf[10]; int i=1; i=1; buf[0]=1; do{ buf[i++]=*pass; } while(*(++pass)); buf[i]=0; Bfile_DeleteFile(pinFile); Bfile_CreateFile(pinFile, 10); file=Bfile_OpenFile(pinFile,_OPENMODE_WRITE); Bfile_WriteFile(file,buf,10); Bfile_CloseFile(file); } unsigned char isFirstUse() { unsigned char buf; int file; Bfile_CreateFile(pinFile,10); file=Bfile_OpenFile(pinFile,_OPENMODE_READ); Bfile_ReadFile(file ,&buf ,1,0); Bfile_CloseFile(file); if(buf!=1)return 1; return 0; } void install() { unsigned int key; unsigned char tampon=1; int file; unsigned char pass1[10]; unsigned char pass2[10]; file=Bfile_OpenFile(pinFile,_OPENMODE_WRITE); Bfile_WriteFile(file,&tampon,1); Bfile_CloseFile(file); locate(0,1); Print((unsigned char*)"FX LOCK - FIRST USE"); PopUpWin(2); locate(3,3); do { PopUpWin(2); locate(3,3); Print((unsigned char*)"Set pass : (1)"); Bdisp_PutDisp_DD(); getUserCode(4,4,pass1); PopUpWin(2); locate(3,3); Print((unsigned char*)"Set pass : (2)"); Bdisp_PutDisp_DD(); getUserCode(4,4,pass2); } while(matchCode(pass1,pass2)==0); Bdisp_PutDisp_DD(); setPassword(pass1); PopUpWin(2); locate(4,3); Print((unsigned char*)"New pass set !"); Bdisp_PutDisp_DD(); GetKey(&key); } void MessLock() { unsigned int key; unsigned char pass1[10]; unsigned char pass2[10]; PopUpWin(5); Bdisp_PutDisp_DD(); locate(3,2); Print((unsigned char*)"FX-9860 is LOCKED"); locate(4,4); Print((unsigned char*)"Enter code..."); getUserCode(6,6,pass1); readPassword(pass2); if(matchCode(pass1,pass2)==0) MessLock(); } void ChangeCode() { unsigned int key; unsigned char pass1[10]; unsigned char pass2[10]; unsigned char pass0[10]; SaveDisp(1); PopUpWin(2); locate(3,3); Print((unsigned char*)"Enter pass :"); Bdisp_PutDisp_DD(); getUserCode(4,4,pass0); readPassword(pass1); if(matchCode(pass0,pass1)==0){ locate(4,3); PopUpWin(2); Print((unsigned char*)"Failed !"); GetKey(&key); } else { do { PopUpWin(2); locate(3,3); Print((unsigned char*)"New pass : (1)"); Bdisp_PutDisp_DD(); getUserCode(4,4,pass1); PopUpWin(2); locate(3,3); Print((unsigned char*)"New pass : (2)"); Bdisp_PutDisp_DD(); getUserCode(4,4,pass2); } while(matchCode(pass1,pass2)==0); setPassword(pass1); PopUpWin(2); locate(4,3); Print((unsigned char*)"New pass set !"); GetKey(&key); } RestoreDisp(1); Bdisp_PutDisp_DD(); } int AddIn_main(int isAppli, unsigned short OptionNum) { unsigned int key; unsigned char pass1[10]; unsigned char pass2[10]; Bdisp_AllClr_DDVRAM(); if(isFirstUse())install(); Bdisp_AllClr_DDVRAM(); locate(1,1); Print((unsigned char*)"[F1] : change code"); locate(1,3); Print((unsigned char*)"[Menu] and power off"); locate(1,4); Print((unsigned char*)" to lock calculator"); locate(2,6); Print((unsigned char*)"Graph 85 is LOCKED"); locate(1,8); Print((unsigned char*)"www.planete-casio.com"); SetQuitHandler(MessLock); SaveDisp(1); while(1){ GetKey(&key); if(key==KEY_CTRL_F1)ChangeCode(); } return 1; } //**************************************************************************** //************** **************** //************** Notice! **************** //************** **************** //************** Please do not change the following source. **************** //************** **************** //**************************************************************************** #pragma section _BR_Size unsigned long BR_Size; #pragma section #pragma section _TOP //**************************************************************************** // InitializeSystem // // param : isAppli : 1 = Application / 0 = eActivity // OptionNum : Option Number (only eActivity) // // retval : 1 = No error / 0 = Error // //**************************************************************************** int InitializeSystem(int isAppli, unsigned short OptionNum) { return INIT_ADDIN_APPLICATION(isAppli, OptionNum); } #pragma section